package Service;

import Dao.UniversityDao;

import org.example.University;
import org.example.University;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class UniversityService {
    public static UniversityService universityService=new UniversityService();
    public static UniversityService getInstance(){
        if (universityService == null){
            universityService = new UniversityService();
        }
        return universityService;
    }
    public static UniversityService getUniversityService() {
        return universityService;
    }

    public Collection<University> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Collection<University> universitys = UniversityDao.universityDao.findAll(connection, conditionList, pagination);
        JdbcHelper.close(connection);
        return universitys;
    }
    public University add(University university) throws SQLException {
        Connection connection =JdbcHelper.getConn();
        return UniversityDao.getUniversityDao().add(university,connection);
    }

    public University upData(University university) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        return UniversityDao.getUniversityDao().upData(university,connection);
    }
    public University find(Integer id) throws SQLException {
        University university = UniversityDao.universityDao.find(id);
        return university;
    }
}
